import "crvpuppet"

define at3_ldapserver($webaddr="", $roleid="") {
  if $AutoMode==true and $CloudCRV==true {
    $ldaprootpw=get_role_attr($webaddr,$roleid,"rootpw")
    $ldapsuffix=get_role_attr($webaddr,$roleid,"suffix")
  }

  
  if ( $AutoMode == false ) or ( $AutoMode==true and $CloudCRV==true ) {

    package { [ "openldap", "openldap-servers", "openldap-clients" ] :
      ensure => installed,
    }

    service { [ "ldap"]:
      hasstatus => true,
      hasrestart => true,
      ensure => running,
      enable => true,
    }

    file { "/etc/openldap/slapd.conf":
      owner => "root",
      group => "root",
      mode => 644,
      content => template("at3_ldapserver/slapd.conf.tpl"),
      notify => Service["ldap"],
    }

  }
  
  if $AutoMode==true and $CloudCRV==true {
    set_role_attr($webaddr,$roleid,"uri","ldap://$ipaddress/")
    set_role_attr($webaddr,$roleid,"ProfileApplied","True")
  }
}

define at3_ldapserver_reverse($webaddr, $roleid) {
  set_role_attr($webaddr,$roleid,"ReverseProfileApplied","True")
}

